package com.qls.ali.biz.order.util;

import com.alibaba.fastjson.JSON;
import com.qls.core.ali.order.common.DailyInfo;
import com.qls.core.ali.order.validaterq.response.InventoryPrice;
import com.qls.core.ali.order.validaterq.response.ValidateRqResult;

import java.util.List;

/**
 * @author doyoung
 */
public class GeneValidateResponse {
    /**
     * 生成下单前校验返回信息
     *
     * @param sucess                 Boolean
     * @param dailyInfos             List<DailyInfo>
     * @param createOrderValidateKey String
     * @return ValidateRqResult
     */
    public static ValidateRqResult gene(Boolean sucess, List<DailyInfo> dailyInfos, String createOrderValidateKey) {
        ValidateRqResult validateRqResponse = new ValidateRqResult();
        if (sucess) {
            StringBuilder inventoryPrice = new StringBuilder("[");
            String quota = "3";
            validateRqResponse.setMessage("验证成功");
            validateRqResponse.setResultCode("0");
            for (DailyInfo dailyInfo : dailyInfos) {
                InventoryPrice inventoryPriceResponse = new InventoryPrice();
                inventoryPriceResponse.setDate(dailyInfo.getDay());
                inventoryPriceResponse.setPrice(dailyInfo.getPrice().toString());
                inventoryPriceResponse.setQuota(quota);
                inventoryPrice.append(JSON.toJSON(inventoryPriceResponse)).append(",");
            }
            inventoryPrice = new StringBuilder(inventoryPrice.toString().replaceAll("\\,$", "]"));
            validateRqResponse.setCreateOrderValidateKey(createOrderValidateKey);
            validateRqResponse.setInventoryPrice(inventoryPrice.toString());
        } else {
            validateRqResponse.setMessage("验证失败");
            validateRqResponse.setResultCode("-3");
        }
        return validateRqResponse;
    }

}
